<template>
  <div class="repairApplyPage">
    <el-row>
      <el-col style="text-align: center;">
        <el-input
          v-model.trim="username"
          placeholder="输入目的地"
          :style="'margin:5px 0px;'"
          @keyup.enter.native="search"
        >
          <el-button slot="append" @click="search">搜索</el-button>
        </el-input>
      </el-col>
    </el-row>
    <el-row>
      <el-col :sm="8">
        <div class="g-title">维保审核数目({{total}}个）</div>
      </el-col>
      <!-- <el-col :sm="16" style="text-align:right">
        <el-button type="primary" @click="addDialogVisible=true" size="mini">申请</el-button>
        <el-button type="warning" @click="editDialogVisible=true" size="mini">修改</el-button>
        <el-button type="danger" @click="del" size="mini">删除</el-button>
      </el-col> -->
    </el-row>
    <el-table
      ref="multipleTable"
      :data="listData"
      tooltip-effect="dark"
      border
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center"></el-table-column>
      <el-table-column prop="pid" label="编号" show-overflow-tooltip width="60" align="center"></el-table-column>
      <el-table-column prop="menuName" label="维修车辆" show-overflow-tooltip align="center"></el-table-column>
      <el-table-column prop="enName" label="维修单位" align="center"></el-table-column>
      <el-table-column prop="url" label="维修项目" align="center"></el-table-column>
      <el-table-column prop="showOrder" label="申请人" align="center"></el-table-column>
      <el-table-column prop="parentName" label="维修预算" align="center"></el-table-column>
      <el-table-column prop="parentName" label="申请时间" align="center"></el-table-column>
      <el-table-column prop="parentName" label="操作" align="center" width="180px">
        <template>
          <div>
            <el-button type="primary" size="mini">审核</el-button>
            <el-button type="danger" size="mini">删除</el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>

    <el-row style="padding: 32px 16px;">
      <el-col>
        <el-pagination
          background
          layout="total, sizes, prev, pager, next, jumper"
          :page-size="pageSize"
          :total="total"
          :current-page="pageNo"
          @current-change="fetchData"
          @size-change="pageSizeChange"
        ></el-pagination>
      </el-col>
    </el-row>
    <add :dialogVisible.sync="addDialogVisible" @finish="addRoleFinish"></add>
    <edit :dialogVisible.sync="editDialogVisible" :data="editData" @finish="editRoleFinish"></edit>
  </div>
</template>
<script>
import "./index.scss";
import { permListJson, delPerm } from "@/api/role";
import add from "./components/add";
import edit from "./components/edit";
export default {
  components: { add, edit },
  data: function() {
    return {
      activeCardName: "all",
      dialogVisible: false,
      roleDialogVisible: false,
      total: 0,
      pageNo: 1,
      pageSize: 10,
      listData: [], //全部数据
      listDataSelected: [], //选中数据
      addDialogVisible: false, //添加
      editDialogVisible: false, //修改基本信息
      editPermsDialogVisible: false, //修改权限
      editData: null, //当前修改的角色
      username:""
    };
  },
  created() {
    this.fetchData();
  },
  methods: {
    //添加完成回调
    addRoleFinish() {
      this.pageNo = 1;
      this.fetchData();
    },
    //编辑完成回调
    editRoleFinish() {
      this.pageNo = 1;
      this.fetchData();
    },
    pageSizeChange(newSize) {
      this.pageSize = newSize;
      this.pageNo = 1;
      this.fetchData();
    },
    handleTabClick() {
      this.pageNo = 1;
      this.fetchData();
    },
    search(){
      this.pageNo=0;
      this.fetchData();
    },
    //修改基本信息
    editPerms(data) {
      this.editData = JSON.parse(JSON.stringify(data));
      this.editDialogVisible = true;
    },
    //删除
    del(data) {
      if(this.listDataSelected.length==0){
        this.$message({
          message: '请选择要删除的行',
          type: 'error'
        })
        return
      }
      this.$confirm("此操作将永久删除, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(async () => {
          let r = await delPerm(data);
          if (r.error == 0) {
            this.$message({
              type: "success",
              message: "删除成功!"
            });
            this.fetchData();
          } else {
            this.$message({
              type: "error",
              message: "删除失败!"
            });
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    async fetchData(pageNo) {
      if (pageNo) {
        this.pageNo = pageNo;
      }
      let params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize
      };
      let data = await permListJson(params);
      this.listData = data.data;
      this.total = data.total;
      this.listDataSelected.splice(0);
    },
    //表格多选
    handleSelectionChange(val) {
      this.listDataSelected.splice(0);
      val.forEach(e => {
        this.listDataSelected.push(e);
      });
    }
  }
};
</script>